package com.ctp.thread.passive;

import javax.swing.table.DefaultTableModel;

import com.ctp.bean.FormBean;
import com.ctp.controller.manager.TraderManager;
import com.ctp.socket.listener.AbstractTraderListener;

public abstract class AbstractTraderListenThread extends Thread implements
		Runnable, ITraderProcessor {

	protected AbstractTraderListener traderListener = null;

	protected TraderManager traderManager = TraderManager.instance();

	public void run() {
		traderListener.listen();
	}

	protected int findFormBySeq(DefaultTableModel tModel, FormBean formBean,
			int column) {
		if (formBean == null) {
			return -2;
		}

		int index = -1;
		for (int i = 0; i < tModel.getRowCount(); i++) {
			if (tModel.getValueAt(i, column).equals(formBean.getSeqNum())) {
				index = i;
				break;
			}
		}

		return index;
	}

	protected int findFormByNum(DefaultTableModel tModel, FormBean formBean,
			int numColunm, int contrColumn) {
		if (formBean == null || formBean.getFormNum() == null || "".equals(formBean.getFormNum())){
			return -2;
		}
		int index = -1;
		for (int i = 0; i < tModel.getRowCount(); i++) {
			if (formBean.getFormNum().equals(tModel.getValueAt(i, numColunm))) {
				index = i;
				break;
			}
		}

		return index;
	}

}
